package com.easy.frame.servers.sys.init;

import com.easy.frame.servers.sys.entity.SysDict;
import com.easy.frame.servers.sys.entity.SysTenantDict;
import com.easy.frame.servers.sys.service.process.SysDictService;
import com.easy.frame.servers.sys.service.tenant.SysTenantDictService;
import com.easy.frame.servers.sys.util.RedisServer4Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 系统初始化操作类
 *
 * @author zzf
 * @date 2020/12/21 11:45
 */
@Component
public class SysStartUpInit implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private SysDictService dictService;
    @Autowired
    private SysTenantDictService tenantDictService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //缓存数据字典信息
        List<SysDict> dictList = dictService.listAll();
        RedisServer4Role.setSysDict(dictList);
        List<SysTenantDict> tenantDictList = tenantDictService.listAll();
        RedisServer4Role.setTenantDictList(tenantDictList);
    }
}
